<script type="text/javascript">
$(function(){
	var pg = App.config.varEdit.ui, pp = pg.params || {}
		, envs = Cache.base.env(App.code);

	var frm = {
		group: pg.seek('group'),
		name: pg.seek('name'),
		value: pg.seek('value'),
		env: pg.seek('env'),
		memo: pg.seek('memo'),
		ver : pg.seek('ver')
	}
	
	frm.env.mac('combo', {
		width: 322,
		boxWidth: 323,
		keyField: 'k',
		displayField: 'v',
		data: envs
	}).val('');

	function getValues(){
		return {
			id: pp.id,
 			projId: pp.projId,
 			group: frm.group.val(),
			name: frm.name.val(),
			value: frm.value.val(),
			env: frm.env.val(),
			memo: frm.memo.val(),
			ver: frm.ver.val()
		};
	}
	
	function setValues(o){
		frm.group.val(o.group);
		frm.name.val(o.name);
		frm.value.val(o.value);
		frm.memo.val(o.memo);
		frm.ver.val(o.ver);
		frm.env.val(o.env);
	}
	setValues(pp);
	
	function validate(p){
		var x = App.validate, v = App.config.validation,
			m = pg.seek('msg').html('');
// 		var	b = x(v.app.code, p.code, m, '英文编码')
// 			&& x(v.app.name, p.name, m, '名字'); 
		return true;
	}
	pg.find('input').blur(function(){
		var pms = getValues();
		if(!validate(pms))
			return;
	});
	pg.seek('ok').click(function(){
		var pms = getValues();
		if (!validate(pms)) {
			return;
		}
		$.post(App.ctx + '/var/save.do', pms, function(rs){
			var ro = mac.eval(rs);
			if (ro.success) {
				pg.callback(ro.data);
				pg.close();
			} else {
				pg.seek('msg').html(mac.msg(ro.data, ro.params));
			}
		});
		return false;
	});
	pg.seek('close').click(pg.close);

	setValues(pp);
});
</script>
<div class="form">
	<div class="item">
		<span class="label">分组：</span>
		<input type="text" name="group" placeholder="请填入组名" />
		<span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">变量名：</span>
		<input type="text" name="name" placeholder="请填入中文名字" />
		<span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">版本号：</span>
		<input type="text" name="ver" placeholder="请填入版本号"/>
		<span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">环境：</span>
		<div class="combo fl" name="env"></div>
		<span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">变量值：</span>
		<textarea name="value" placeholder="请填入变量值"></textarea>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">备注：</span>
		<textarea name="memo" placeholder="请填入备注"></textarea>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">&nbsp;</span>
		<div name="msg" class="msg"></div>
		<div class="clear"></div>
	</div>
	<div class="bottom">
		<button name="ok">确定</button>
		&nbsp;&nbsp;
		<button name="close">取消</button>
	</div>
</div>